|
|
|
| |
|
|
|
|
entry. Setting the control's focus is best done outside of any other control's GotFocus or LostFocus event. Also, because a user can use the mouse to skip over any field on the form, placing independent content validation routines within the controls' events means that users may skip important validation steps in the process. |
|
|
|
|
|
|
|
|
|
|
To set up the form-level validation, first add a single command button to the form. Set its Name property to cmdOK and its caption property to &OK. Now add another label/textbox pair to the form. Set the label caption to High/Low. Set the textbox Name property to txtHighLow and the text property to blank. Refer to Figure 5.8 for sizing and placement information. |
|
|
|
|
|
|
|
|
Figure 5.8.
Adding the High/Low control
and OK button to the form. |
|
|
|
|
|
|
|
|
Next add Listing 5.6 to the cmdOK_click event. |
|
|
|
|
|
|
|
|
Listing 5.6. The form-level validation routine to check for values in a range. |
|
|
|
|
|
|
|
|
Private Sub cmdOK_Click()
'
Dim intHigh As Integer
Dim intLow As Integer
Dim strHighLowMsg As String
'
intHigh = 100
intLow = 1
strHighLowMsg = "High/Low field must contain a value between " & _
CStr(intLow) & " and " & CStr(intHigh)
'
If Val(txtHighLow) < intLow Or Val(txtHighLow) > intHigh Then
MsgBox strHighLowMsg
txtHighLow.SetFocus
End If
'
End Sub |
|
|
|
|
|